<?php

namespace App\Http\Controllers;

use App\Models\News;
use App\Models\NewsSort;
use Illuminate\Http\Request;

class IndexController extends Controller
{
    public function index()
    {
        $newsSort = NewsSort::pluck('id', 'name')->toArray();
        $news = [];
        foreach ($newsSort as $key => $value){
            switch ($key){
                case 'bridge':
                    $news[$key] = News::where('sort_id', $value)->get();
                    break;
                default:
                    $news[$key] = News::where('sort_id', $value)->limit(2)->get();
                    break;
            }
        }


        $news['newsSort'] = $newsSort;
        return view('welcome', $news);
    }
}
